package com.aier.proxy.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.aier.admin.entity.SysCity;
import com.aier.admin.entity.mapper.SysCityRowMapper;
import com.aier.common.dao.ICommonDAO;
import com.aier.proxy.service.IUserCreateSchoolService;
import com.aier.school.entity.School;
import com.aier.school.entity.mapper.SchoolRowMapper;

@Component("userCreateSchoolService")
public class UserCreateSchoolServiceImpl_J implements IUserCreateSchoolService {

    @Resource(name = "commonDao")
    private ICommonDAO commonDao;

    public void setCommonDao(ICommonDAO commonDao) {
        this.commonDao = commonDao;
    }

    /**
     * 查询已创建的学校集合
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<School> searchSchool(Integer pid, Integer cid) {
        return (List<School>) commonDao.list(
                "select * from school where pid=? and cid in (select cid from sys_city where FIND_IN_SET(cid, getChildLst(?)))", new Object[] {
                    pid, cid }, new SchoolRowMapper());
    }

    /**
     * 根据代理id查询该代理的下的城市
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<SysCity> searchProxyCity1(Integer pid) {
        return (List<SysCity>) commonDao
                .list("select * from sys_city sc left join proxy_city pc on sc.cid=pc.cid where pc.pid=?",
                        new Object[] { pid }, new SysCityRowMapper());
    }

    @Override
    public School searchSchool(String scName) {
        return (School) commonDao.listByObject(
            "select * from school where name=?", new Object[] { scName },
            new SchoolRowMapper());
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<School> searchSchool(int pid) {
        return (List<School>) commonDao.list(
                "select * from school where pid=?", new Object[] {pid }, new SchoolRowMapper());
    }

    

}
